package cn.net.sinodata.system.controller.system;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import cn.net.sinodata.common.log.annotation.Log;
import cn.net.sinodata.common.web.core.BaseController;
import cn.net.sinodata.common.mybatis.core.page.PageQuery;
import cn.net.sinodata.common.core.domain.R;
import cn.net.sinodata.common.core.validate.AddGroup;
import cn.net.sinodata.common.core.validate.EditGroup;
import cn.net.sinodata.common.log.enums.BusinessType;
import cn.net.sinodata.common.excel.utils.ExcelUtil;
import cn.net.sinodata.system.domain.vo.PmMonitorProductVo;
import cn.net.sinodata.system.domain.bo.PmMonitorProductBo;
import cn.net.sinodata.system.service.IPmMonitorProductService;
import cn.net.sinodata.common.mybatis.core.page.TableDataInfo;

/**
 * 监控产品管理
 *
 * @author yinliangyun
 * @date 2025-10-30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/monitorProduct")
public class PmMonitorProductController extends BaseController {

    private final IPmMonitorProductService pmMonitorProductService;

    /**
     * 查询监控产品管理列表
     */
    @GetMapping("/list")
    public TableDataInfo<PmMonitorProductVo> list(PmMonitorProductBo bo, PageQuery pageQuery) {
        return pmMonitorProductService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出监控产品管理列表
     */
    @Log(title = "监控产品管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PmMonitorProductBo bo, HttpServletResponse response) {
        List<PmMonitorProductVo> list = pmMonitorProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "监控产品管理", PmMonitorProductVo.class, response);
    }

    /**
     * 获取监控产品管理详细信息
     *
     * @param id 主键
     */
    @GetMapping("/{id}")
    public R<PmMonitorProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(pmMonitorProductService.queryById(id));
    }

    /**
     * 新增监控产品管理
     */
    @Log(title = "监控产品管理", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PmMonitorProductBo bo) {
        return toAjax(pmMonitorProductService.insertByBo(bo));
    }

    /**
     * 修改监控产品管理
     */
    @Log(title = "监控产品管理", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PmMonitorProductBo bo) {
        return toAjax(pmMonitorProductService.updateByBo(bo));
    }

    /**
     * 删除监控产品管理
     *
     * @param ids 主键串
     */
    @Log(title = "监控产品管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(pmMonitorProductService.deleteWithValidByIds(List.of(ids), true));
    }

}
